package com.alks.function.service.impl.pcorder;

import com.alks.function.data.dto.CollectionPointDto;
import com.alks.function.data.request.yield.CollectionPointRequest;
import com.alks.function.mapper.PcOrderHeadMapping;
import com.alks.function.service.OrderAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.Future;

/**
 * @author:xxxxx
 * @create: 2023-07-15 17:21
 * @Description: 异步调用查询采集节点
 */
@Service
public class OrderAsyncServiceImpl implements OrderAsyncService {
    @Autowired
    PcOrderHeadMapping pcOrderHeadMapping;
    @Override
    @Async
    public Future<Long> getCollectionTotal(CollectionPointDto dto, CollectionPointRequest request) {
        Future<Long> future = new AsyncResult<>(pcOrderHeadMapping.getCollectionTotal(request));
        return future;
    }

    @Override
    @Async
    public Future<BigDecimal> getCollectionOrders(CollectionPointDto dto, CollectionPointRequest request) {
        BigDecimal orders = pcOrderHeadMapping.getCollectionOrders(request);
        if (orders ==null){
            orders = new BigDecimal(0);
        }
        Future<BigDecimal> future = new AsyncResult<>(orders.setScale(2, RoundingMode.HALF_UP));
        return future;
    }
}
